﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using Eacademy.Domain.Abstractions;
using Eacademy.Domain.Models;
using Eacademy.Library.Actions;
using Eacademy.Library.Membership;

namespace Eacademy.Areas.Mentor.Controllers
{
    [ProfileControllerFilter]
    public class SubjectsController : Controller
    {
        private const int DefaultPageSize = 10;
        private ISubjectRepository _subjectRepository;
        private IMentorRepository _mentorRepository;
        private ILessonRepository _lessonRepository;

        CustomMembershipProvider provider = (CustomMembershipProvider)Membership.Provider;

        public SubjectsController(ISubjectRepository subjectRepository, IMentorRepository mentorRepository, ILessonRepository lessonRepository)
        {
            _subjectRepository = subjectRepository;
            _mentorRepository = mentorRepository;
            _lessonRepository = lessonRepository;
        }


        public ActionResult Index(int? page)
        {
            int currentPageIndex = page.HasValue ? (page.Value <= 0 ? 0 : page.Value - 1) : 0;
            SubjectListFilterViewModel subjectListFilterViewModel = new SubjectListFilterViewModel();
            AdminSubjectListViewModel adminSubjectListViewModel = new AdminSubjectListViewModel();
            int totalcount = 0;
            List<SubjectCompactViewModel> subjectList = _subjectRepository.GetSubjectsByMentorId(currentPageIndex + 1, DefaultPageSize,(int)provider.User.UserId, subjectListFilterViewModel, out totalcount);
            adminSubjectListViewModel.SubjectList = subjectList.ToPagedList(currentPageIndex, DefaultPageSize, totalcount);

            return View(adminSubjectListViewModel);
        }

    }
}
